// JavaScript Document
var gameModes = new Array();
var gameTracks = new Array();

function element(){
	var list = new Array();
	
	this.add=function(Id,Name) {
		list[list.length] = {id:Id,name:Name};
	}
	
	this.append=function(selectElement) {
		selectElement.disabled=false;
		for(var i=0;i<list.length;i++) {
			selectElement.options[i+1] = new Option(list[i].name,list[i].id);
		}
	}
}

function addMode(gameId, modeId, modeName) {
		if(!gameModes[gameId]) 
			gameModes[gameId] = new element();
		gameModes[gameId].add(modeId, modeName);
}

function addTrack(gameId, trackId, trackName) {
		if(!gameTracks[gameId]) 
			gameTracks[gameId] = new element();
		gameTracks[gameId].add(trackId, trackName);
}

function activateMode(gameSelect, modeSelect) {
	var gameid = gameSelect.options[gameSelect.selectedIndex].value;
	var gamevalue = gameModes[gameid];
	if(gamevalue) 
		gamevalue.append(modeSelect);
	else {
		clearSelect(modeSelect);
		modeSelect.disabled=true;
	}
	
}

function activateTrack(gameSelect, trackSelect) {
	var gameid = gameSelect.options[gameSelect.selectedIndex].value;
	var gamevalue = gameTracks[gameid];
	if(gamevalue) 
		gamevalue.append(trackSelect);
	else {
		clearSelect(trackSelect);
		trackSelect.disabled=true;
	}
}

function clearSelect(whatselect) {

	var i = 0;
	var select_url = whatselect.options;
	var opt = new Option(whatselect.options[0].text,whatselect.options[0].value);
		
	for (i = select_url.length; i >= 0; --i) {
		select_url[i] = null;
	}
	whatselect.options[0] = opt;
}



function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\n\nConstructor: "+obj.constructor : "")+"\n\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\n\nValue: "+obj;
   }
}


